package Service.Impl;

import Dao.DateImpl.TeacherDaoImpl;
import Model.Teacher;
import Service.TeacherInter;

import java.util.Scanner;

/**
 * 业务逻辑 查询老师信息  录入老师信息--》数据访问
 */
public class TeacherInterImpl implements TeacherInter {
    TeacherDaoImpl teacherDao = new TeacherDaoImpl();

    @Override
    public void showTeacher(Teacher[] teacher, int len) {
        //当前业务层调用数据访问层获取数据

        teacherDao.showTeacherDao(teacher, len);
    }

    @Override
    public void addTeacher(Teacher[] teacher, Teacher person) {
        //当前业务层调用数据访问层获取数据

        teacherDao.addTeacherDao(teacher, person);
    }


    @Override
    public boolean delTeacher(Teacher teacher[], String uid, int num) {
        //业务逻辑层调用数据访问层Dao，实现删除操作

        if (teacherDao.delTeacherDao(teacher, uid, num)) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void updateTeacher(Teacher[] teacher, String uid, int num) {

        int j;
        if (teacherDao.updateTeacherDao(teacher, uid, num) != null) {
            j = teacherDao.updateTeacherDao(teacher, uid, num);
            Scanner scanner = new Scanner(System.in);

            System.out.println("你要更新的老师姓名是：" + teacher[j].getName());
            System.out.println("请输入更新的姓名:");
            String name = scanner.nextLine();
            if (!name.equals("")) {
                teacher[j].setName(name);
            }

            System.out.println("你要更新的老师年龄是：" + teacher[j].getAge());
            System.out.println("请输入更新的年龄:");
            String age = scanner.nextLine();
            if (!age.equals("")) {
                teacher[j].setAge(Integer.valueOf(age));
            }


            System.out.println("你要更新的老师性别是：" + teacher[j].getSex());
            System.out.println("请输入更新的性别:");
            String sex = scanner.nextLine();
            if (!sex.equals("")) {
                teacher[j].setSex(sex);
            }


            System.out.println("你要更新的老师科目是：" + teacher[j].getSubject());
            System.out.println("请输入更新的科目是:");
            String subject = scanner.nextLine();
            if (!subject.equals("")) {
                teacher[j].setSubject(subject);
            }

            System.out.println("数据更新成完成");

        } else {
            System.out.println("你要更新不存在");
        }
    }
}
